package com.example.performance.jmh.annotation;

import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;

import java.util.concurrent.TimeUnit;

/**
 * @author zpMeng
 * @since 9/18/2024
 */
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@Warmup(iterations = 3, time = 1)
@Measurement(iterations = 3, time = 1)
@Threads(8)
@Fork(1)
@State(Scope.Benchmark)
public class A6StateBenchmark {
    Person person = new Person(21, "ben", "benchmark");
    volatile double x = Math.PI;

    @Benchmark
    public void measureShared(A6StateBenchmark state) {
        state.x++;
    }

    public static void main(String[] args) throws RunnerException {
        Options options = new OptionsBuilder().include(A6StateBenchmark.class.getSimpleName())
                .build();
        new Runner(options).run();
    }
}
